// pages/post4/post4.js
const app = getApp(), core = require('../../utils/core'), util = require('../../utils/util'), WeValidator = require('../../utils/we-validator');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    job: {},
    educationLevels: [],
    experienceOptions: [],
    selectedEducationLevel: null,
    selectedExperienceOption: null,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getOpenerEventChannel().on('jobTransfer', job => {
      this.setData({job: job});
    });
    util.getWorkExperienceOptions().then(options => {
      this.setData({experienceOptions: options});
    });
    util.getEducationLevels().then(levels => {
      this.setData({educationLevels: levels});
    });
  },
  bindEducationLevelChange: function(event) {
    let items = event.detail.items;
    let selectedLevel = items[0];
    this.setData({selectedEducationLevel: selectedLevel, 'job.education_level_id': selectedLevel.id});
  },
  bindWorkExperienceChange: function(event) {
    let items = event.detail.items;
    let selectedOption = items[0];
    this.setData({selectedExperienceOption: selectedOption, 'job.work_experience_id': selectedOption.id});
  },
  bindNextStep: function () {
    let validator = new WeValidator({
      rules: {
        education_level_id: {required:true},
        work_experience_id: {required:true},
      },
      messages: {
        education_level_id: {required:'请选择人员学历要求'},
        work_experience_id: {required:'请选择工作年限要求'},
      }
    });
    if(!validator.checkData(this.data.job)) {
      return;
    }
    wx.navigateTo({url: '/pages/post6/post6', success: res => {
      res.eventChannel.emit("jobTransfer", this.data.job);
    }});
  },
});
